package cn.shiro.shiroservice.moudle.db.service.impl;

import cn.shiro.shiroservice.moudle.db.mapper.DataBaseMapper;
import cn.shiro.shiroservice.moudle.db.pojo.dto.TableStructureDTO;
import cn.shiro.shiroservice.moudle.db.service.DatabaseService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import java.util.List;
import java.util.Map;

/**
 * &#064;Time 2024 一月 星期三 23:02
 *
 * @author ShangGuan
 */
public class DatabaseServiceImpl implements DatabaseService {


    private  final DataBaseMapper dataBaseMapper;
    public DatabaseServiceImpl (DataBaseMapper dataBaseMapper){
        this.dataBaseMapper=dataBaseMapper;
    }

    @Override
    public String getDataBaseVersion() {
        return dataBaseMapper.getDataBaseVersion();
    }

    @Override
    public List<String> showDatabase() {
        return dataBaseMapper.showDatabase();
    }

    @Override
    public List<String> showTables() {
        return dataBaseMapper.showTables();
    }

    @Override
    public List<TableStructureDTO> getTableStructure(String tableName) {
        return dataBaseMapper.getTableStructure(tableName);
    }

    @Override
    public List<Map<String,Object>> selectTable(String tableName) {
        return dataBaseMapper.selectTable(tableName);
    }

    @Override
    public PageInfo<Map<String,Object>> page(String tableName,Integer pageNum,Integer pageSize) {
        try (Page<Object> page = PageHelper.startPage(pageNum, pageSize)) {
            List<Map<String, Object>> result = dataBaseMapper.selectTable(tableName);
            return new PageInfo<>(result);
        }
    }
}
